package com.event.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.event.pojo.QaQuestion;
import com.event.mapper.QaQuestionMapper;
import com.event.service.QaQuestionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 问题列表 服务实现类
 * </p>
 *
 * @author event
 * @since 2021-10-06
 */
@Service
public class QaQuestionServiceImpl extends ServiceImpl<QaQuestionMapper, QaQuestion> implements QaQuestionService {
    @Autowired
    QaQuestionMapper questionMapper;
    @Override
    public List<QaQuestion> selectQuestion(QaQuestion qa) {
        QueryWrapper<QaQuestion> wrapper = new QueryWrapper<>();
        wrapper.eq(qa.getQuestionId()!=null,"question_id",qa.getQuestionId());
        wrapper.eq(qa.getTitle()!=null,"title",qa.getTitle());
        wrapper.eq(qa.getContent()!=null,"content",qa.getContent());
        wrapper.eq(qa.getViews()!=null,"views",qa.getViews());
        wrapper.eq(qa.getReplys()!=null,"replys",qa.getReplys());
        wrapper.eq(qa.getCreatetime()!=null,"createtime",qa.getCreatetime());
        wrapper.eq(qa.getReplytime()!=null,"replytime",qa.getReplytime());
        wrapper.eq(qa.getSponorid()!=null,"sponorid",qa.getSponorid());
        wrapper.eq(qa.getLikes()!=null,"likes",qa.getLikes());
        wrapper.eq(qa.getNotlikes()!=null,"notlikes",qa.getNotlikes());
        wrapper.eq(qa.getApplaud()!=null,"applaud",qa.getApplaud());
        wrapper.eq(qa.getSource()!=null,"source",qa.getSource());
        wrapper.eq(qa.getType()!=null,"type",qa.getType());
        wrapper.eq(qa.getLimittime()!=null,"limittime",qa.getLimittime());
        wrapper.eq(qa.getReplyOpenname()!=null,"reply_openname",qa.getReplyOpenname());
        wrapper.eq(qa.getPass()!=null,"pass",qa.getPass());
        List<QaQuestion> qaQuestions = questionMapper.selectList(wrapper);
        return qaQuestions;

    }

    @Override
    @Transactional
    public int updateQuestion(QaQuestion qa) {
        return questionMapper.updateById(qa);
    }

    @Override
    public int deleteQuestion(QaQuestion qa) {
        return questionMapper.deleteById(qa.getQuestionId());
    }

    @Override
    @Transactional
    public int insertQuestion(QaQuestion qa) {
        return questionMapper.insert(qa);
    }
}
